import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import type { Rule } from 'ant-design-vue/es/form'

export const useGroupFormRules = () => {
  const { t } = useI18n()
  
  return computed<Record<string, Rule[]>>(() => ({
    name: [
      { required: true, message: t('setting.groupNameRequired'), trigger: 'blur' },
      { min: 2, max: 50, message: t('setting.groupNameLength'), trigger: 'blur' }
    ],
    code: [
      { required: true, message: t('setting.groupCodeRequired'), trigger: 'blur' },
      { pattern: /^[a-zA-Z0-9_]+$/, message: t('setting.groupCodePattern'), trigger: 'blur' }
    ],
    icon: [
      { required: true, message: t('setting.groupIconRequired'), trigger: 'change' }
    ],
    sort: [
      { required: true, message: t('setting.groupSortRequired'), trigger: 'change' }
    ]
  }))
}

export const useConfigFormRules = () => {
  const { t } = useI18n()
  
  return computed<Record<string, Rule[]>>(() => ({
    groupId: [
      { required: true, message: t('setting.groupRequired'), trigger: 'change' }
    ],
    configName: [
      { required: true, message: t('setting.configNameRequired'), trigger: 'blur' },
      { min: 2, max: 50, message: t('setting.configNameLength'), trigger: 'blur' }
    ],
    configKey: [
      { required: true, message: t('setting.configKeyRequired'), trigger: 'blur' },
      { pattern: /^[a-zA-Z0-9_]+$/, message: t('setting.configKeyPattern'), trigger: 'blur' }
    ],
    valueType: [
      { required: true, message: t('setting.valueTypeRequired'), trigger: 'change' }
    ],
    configValue: [
      { required: true, message: t('setting.configValueRequired'), trigger: 'blur' }
    ]
  }))
} 